package gui.view.android.graphics;

import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;

import com.nightpiter.view.graphics.Color;
import com.nightpiter.view.graphics.PathEffect;
import com.nightpiter.view.graphics.Shader;
import com.nightpiter.view.graphics.abstaractions.AbstractPaint;

public class JavaPaint implements AbstractPaint {

	public static String FONT_NAME = Font.SANS_SERIF;

	public static int FONT_STYLE = Font.PLAIN;

	public static Object castAntiAlias(boolean aa) {

		if (aa == true) {
			return RenderingHints.VALUE_ANTIALIAS_ON;
		} else {
			return RenderingHints.VALUE_ANTIALIAS_OFF;
		}
	}

	public static int castCap(Cap aCap) {

		if (aCap == Cap.BUTT) {
			return BasicStroke.CAP_BUTT;
		} else if (aCap == Cap.ROUND) {
			return BasicStroke.CAP_ROUND;
		} else {
			return BasicStroke.CAP_SQUARE;
		}
	}

	private Shader shader;
	private PathEffect effect;

	private boolean valueAntiAlias;
	private float strokeWidth;
	private Cap strokeCap;
	private int color;
	private float textSize;
	private Style style;

	public JavaPaint() {
		valueAntiAlias = false;
		strokeWidth = 1;
		strokeCap = Cap.BUTT;
		color = Color.BLACK;
		textSize = 12;
		style = Style.FILL_AND_STROKE;
		effect = null;
		shader = null;
	}

	@Override
	public int getColor() {
		return color;
	}

	@Override
	public PathEffect getPathEffect() {
		return effect;
	}

	@Override
	public Cap getStrokeCap() {
		return strokeCap;
	}

	@Override
	public float getStrokeWidth() {
		return strokeWidth;
	}

	@Override
	public Style getStyle() {
		return style;
	}

	@Override
	public float getTextSize() {
		return textSize;
	}

	@Override
	public boolean isAntiAlias() {
		return valueAntiAlias;
	}

	@Override
	public float measureText(String text) {
		FontRenderContext frc = new FontRenderContext(null, valueAntiAlias,
				true);
		Font font = new Font(FONT_NAME, FONT_STYLE, (int) textSize);
		GlyphVector gv = font.createGlyphVector(frc, text);
		Shape outline = gv.getOutline();
		return (float) outline.getBounds2D().getWidth();
	}

	@Override
	public void setAlpha(int a) {
		color = Color.argb(a, Color.red(color), Color.green(color), Color
				.blue(color));
	}

	@Override
	public void setAntiAlias(boolean aa) {
		valueAntiAlias = aa;
	}

	@Override
	public void setARGB(int a, int r, int g, int b) {
		color = Color.argb(a, r, g, b);
	}

	@Override
	public void setColor(int color) {
		this.color = color;
	}

	@Override
	public PathEffect setPathEffect(PathEffect effect) {
		this.effect = effect;
		return null;
	}

	@Override
	public void setStrokeCap(Cap cap) {
		strokeCap = cap;
	}

	@Override
	public void setStrokeWidth(float width) {
		strokeWidth = width;
	}

	@Override
	public void setStyle(Style style) {
		this.style = style;
	}

	@Override
	public void setTextSize(float textSize) {
		this.textSize = textSize;
	}

	@Override
	public Shader getShader() {
		return shader;
	}

	@Override
	public void setShader(Shader shader) {
		this.shader = shader;
	}

}
